//============================================================================
// Name        : Run.h
// Author      : lucmir@dcc.ufmg.br
// Description :
//============================================================================

#ifndef __RUN_H__
#define __RUN_H__

#include <stdio.h>
#include <string>
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <istream>
#include <ostream>
#include <iterator>
#include <sstream>

#include "Registry.h"
#include "Lexon.h"

//#define RUN_TEST

class Run {

	public:

		/**
		 *  Inner class used during the run generation
		 */
		class TermInfo {

			unsigned int docId;
			unsigned int freq;

			public:

				TermInfo(unsigned int docId, unsigned int freq) : docId(docId), freq(freq) {
				}

				TermInfo(unsigned int docId) : docId(docId), freq(1) {
				}

				bool operator<(const TermInfo &t) const {
					if (this->docId != t.docId) {
						return (this->docId < t.docId);
					}
					return (this->freq < t.freq);
				}

				bool operator>(const TermInfo &t) const {
					return !(*this < t);
				}

				unsigned int getDocId() {
					return this->docId;
				}

				unsigned int getFreq() {
					return this->freq;
				}

				void setDocId(unsigned int docId) {
					this->docId = docId;
				}

				void setFreq(unsigned int freq) {
					this->freq = freq;
				}

				void incFreq() {
					this->freq++;
				}

		};

	private:

		std::map<unsigned int, std::list<TermInfo *> > registrySet;
		unsigned int registryCount;

	public:

		Run();
		~Run();

		void insert(unsigned int docId, unsigned int termId);
		unsigned int getLen();
		void clear();
		void printToFile(std::string fileName, Lexon *lexon);		// Delete and print to file each registry
		bool readFromFile(std::ifstream &file, Registry &registry);

};

#endif
